/*
 *	Atom database
 *
 *	Copyright (C) 2011 XiaoJSoft Studio. All Rights Reserved.
 *	Copyright (C) Ji WenCong <whs_jwc@163.com>
 *
 *	kasprintf (copied & modified from Linux Kernel):
 *	Copyright (C) Linus Torvalds <torvalds@klaava.Helsinki.Fi>
 *
 *	This program is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "../../cross.h"

#ifndef DEFINED_CE

	static char *chemical_enames[] = {
		"e", \
		"H", "He", \
		"Li", "Be", "B", "C", "N", "O", "F", "Ne", \
		"Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", \
		"K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", \
		"Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb", "Te", "I", "Xe", \
		"Cs", "Ba", "La", "Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", \
		"Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn"
	};

	static char *chemical_enames_eng[] = {
		"Electron", \
		"Hydrogen", "Helium", \
		"Lithium", "Beryllium", "Boron", "Carbon", "Nitrogen", "Oxygen", "Fluorine", "Neon", \
		"Sodium", "Magnesium", "Aluminum", "Silicon", "Phosphorus", "Sulfur", "Chlorine", "Argon", \
		"Potassium", "Calcium", "Scandium", "Titanium", "Vanadium", "Chromium", "Manganese", "Iron", "Cobalt", "Nickel", "Copper", "Zinc", "Gallium", "Germanium", "Arsenic", "Selenium", "Bromine", "Krypton", \
		"Rubidium", "Strontium", "Yttrium", "Zirconium", "Niobium", "Molybdenum", "Technetium", "Ruthenium", "Rhodium", "Palladium", "Silver", "Cadmium", "Indium", "Tin", "Antimony", "Tellurium", "Iodine", "Xenon", \
		"Cesium", "Barium", "Lanthanum", "Cerium", "Praseodymium", "Neodymium", "Promethium", "Samarium", "Europium", "Gadolinium", "Terbium", "Dysprosium", "Holmium", "Erbium", "Thulium", "Ytterbium", "Lutetium", "Hafnium", "Tantalum", "Tungsten", "Rhenium", "Osmium", "Iridium", "Platinum", "Gold", "Mercury", "Thallium", "Lead", "Bismuth", "Polonium", "Astatine", "Radon", \
		"Francium", "Radium", "Actinium", "Thorium", "Protactinium", "Uranium", "Neptunium", "Plutonium", "Americium", "Curium", "Berkelium", "Californium", "Einsteinium", "Fermium", "Mendelevium", "Nobelium", "Lawrencium", "Rutherfordium", "Dubnium", "Seaborgium", "Bohrium", "Hassium", "Meitnerium", "Darmstadtium", "Roentgenium", "Ununbium"
	};

	static char *chemical_grstate_conf[] = {
		"N/A", \
		"1s", "1s(2)", \
		"1s(2)2s", "1s(2)2s(2)", "1s(2)2s(2)2p", "1s(2)2s(2)2p(2)", "1s(2)2s(2)2p(3)", "1s(2)2s(2)2p(4)", "1s(2)2s(2)2p(5)", "1s(2)2s(2)2p(6)", \
		"[Ne]3s", "[Ne]3s(2)", "[Ne]3s(2)3p", "[Ne]3s(2)3p(2)", "[Ne]3s(2)3p(3)", "[Ne]3s(2)3p(4)", "[Ne]3s(2)3p(5)", "[Ne]3s(2)3p(6)", \
		"[Ar]4s", "[Ar]4s(2)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xe]4f(14)5d(10)6s", "[Xe]4f(14)5d(10)6s(2)", "[Hg]6p", "[Hg]6p(2)", "[Hg]6p(3)", "[Hg]6p(4)", "[Hg]6p(5)", "[Hg]6p(6)", \
		"[Rn]7s", "[Rn]7s(2)", "[Rn]6d7s(2)", "[Rn]6d(2)7s(2)", "[Rn]5f(2)6d7s(2)", "[Rn]5f(3)6d7s(2)", "[Rn]5f(4)6d7s(2)", "[Rn]5f(6)7s(2)", "[Rn]5f(7)7s(2)", "[Rn]5f(7)6d7s(2)", "[Rn]5f(9)7s(2)", "[Rn]5f(10)7s(2)", "[Rn]5f(11)7s(2)", "[Rn]5f(12)7s(2)", "[Rn]5f(13)7s(2)", "[Rn]5f(14)7s(2)", "[Rn]5f(14)7s(2)7p?", "[Rn]5f(14)6d(2)7s(2)?", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A"
	};

	static char *chemical_grstate_level[] = {
		"N/A", \
		"2S1/2", "1S0", \
		"2S1/2", "1S0", "2P(.)1/2", "3P0", "4S(.)3/2", "3P2", "2P(.)3/2", "1S0", \
		"2S1/2", "1S0", "2P(.)1/2", "3P0", "4S(.)3/2", "3P2", "2P(.)3/2", "1S0", \
		"2S1/2", "1S0", "2D3/2", "3F2", "4F3/2", "7S3", "6S5/2", "5D4", "4F9/2", "3F4", "2S1/2", "1S0", "2P(.)1/2", "3P0", "4S(.)3/2", "3P2", "2P(.)3/2", "1S0", \
		"2S1/2", "1S0", "2D3/2", "3F2", "6D1/2", "7S3", "6S5/2", "5F5", "4F9/2", "1S0", "2S1/2", "1S0", "2P(.)1/2", "3P0", "4S(.)3/2", "3P2", "2P(.)3/2", "1S0", \
		"2S1/2", "1S0", "2D3/2", "1G(.)4", "4I(.)9/2", "5I4", "6H(.)5/2", "7F0", "8S(.)7/2", "9D(.)2", "6H(.)15/2", "5I8", "4I(.)15/2", "3H6", "2F(.)7/2", "1S0", "2D3/2", "3F2", "4F3/2", "5D0", "6S5/2", "5D4", "4F9/2", "3D3", "2S1/2", "1S0", "2P(.)1/2", "3P0", "4S(.)3/2", "3P2", "2P(.)3/2", "1S0", \
		"2S1/2", "1S0", "2D3/2", "3F2", "(4,3/2)11/2", "(9/2,3/2)(.)6", "(4,3/2)11/2", "7F0", "8S(.)7/2", "9D(.)2", "6H(.)15/2", "5I8", "4I(.)15/2", "3H6", "2F(.)7/2", "1S0", "2P(.)1/2?", "3F2?", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A", "N/A"
	};

	static double chemical_heavy[] = {
		0.0, \
		1.008, 4.003, \
		6.941, 9.012, 10.81, 12.01, 14.01, 16.00, 19.00, 20.18, \
		22.99, 24.31, 26.98, 28.09, 30.97, 32.06, 35.45, 39.95, \
		39.10, 40.08, 44.96, 47.87, 50.94, 52.00, 54.94, 55.85, 58.93, 58.69, 63.55, 65.41, 69.72, 72.64, 74.92, 78.96, 79.90, 83.80, \
		85.47, 87.62, 88.91, 91.22, 92.91, 95.94, 98, 101.1, 102.9, 106.4, 107.9, 112.4, 114.8, 118.7, 121.8, 127.6, 126.9, 131.3, \
		132.9, 137.3, 138.9, 140.1, 140.9, 144.2, 145.0, 150.4, 152.0, 157.3, 158.9, 162.5, 164.9, 167.3, 168.9, 173.0, 175.0, 178.5, 180.9, 183.8, 186.2, 190.2, 192.2, 195.1, 197.0, 200.6, 204.4, 207.2, 209.0, 209.0, 210.0, 222.0, \
		223.0, 226.0, 227.0, 232.0, 231.0, 238.0, 237.0, 244.0, 243.0, 247.0, 247.0, 251.0, 252.0, 257.0, 258.0, 259.0, 262.0, 261.0, 262.0, 266.0, 264.0, 277.0, 268.0, 281.0, 272.0, 285.0
	};

	static double chemical_ionization_energy[] = {
		0.0, \
		13.5984, 	24.5874, \
		5.3917, 9.3227, 8.2980, 11.2603, 14.5341, 13.6181, 17.4228, 21.5645, \
		5.1391, 7.6462, 5.9858, 8.1517, 10.4867, 10.3600, 12.9676, 15.7596, \
		4.3407, 6.1132, 6.5615, 6.8281, 6.7462, 6.7665, 7.4340, 7.9024, 7.8810, 7.6399, 7.7264, 9.3942, 5.9993, 7.8994, 9.7886, 9.7524, 11.8138, 13.9996, \
		4.1771, 5.6949, 6.2173, 6.6339, 6.7589, 7.0924, 7.2800, 7.3605, 7.4589, 8.3369, 7.5762, 8.9938, 5.7864, 7.3439, 8.6084, 9.0096, 10.4513, 12.1298, \
		3.8939, 5.2117, 5.5769, 5.5387, 5.4730, 5.5250, 5.5820, 5.6437, 5.6704, 6.1498, 5.8638, 5.9389, 6.0215, 6.1077, 6.1843, 6.2542, 5.4259, 6.8251, 7.5496, 7.8640, 7.8335, 8.4382, 8.9670, 8.9588, 9.2255, 10.4375, 6.1082, 7.4167, 7.2855, 8.4140, 0, 10.7485, \
		4.0727, 5.2784, 5.3807, 6.3067, 5.8900, 6.1939, 6.2657, 6.0260, 5.9738, 5.9914, 6.1979, 6.2817, 6.3676, 6.5000, 6.5800, 6.6500, 4.9000, 6.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000
	};

	static int chemical_ecount = 112;

	#define DEFINED_CE
#endif

void traceElementInfo(int idx, char *ename, char *ename_eng, double weight, double ev, char *grconf, char *grlevel);
int atomExist(char *symbol);
void listElements(int from, int to);
char* getAtomGStateLevel(char *symbol);
double getAtomIonizationEnergy(char *name, int *succeed);
char* getAtomGStateConf(char *symbol);
double getAtomHeavy(char *name, int *succeed);

char* getAtomEnglishName(char *symbol);
